import random

WIDTH = 250
HEIGHT = 250

unit = 50

BACK_COLOR = (200, 0, 0)
ten_x=2
ten_y=2

class MyRect:
    def __init__(self, mid_x, mid_y, clr):
        self.mid_x = mid_x
        self.mid_y = mid_y
        self.clr = clr

    def Draw(self):
        rc = Rect((self.mid_x - unit // 2, self.mid_y - unit // 2), (unit, unit))
        screen.draw.filled_rect(rc, self.clr)

rc_list = []

def Init():
    global rc_list
    r=ten_x
    c=ten_y
    clr=(0,200,200)
    rc1 = MyRect(r * unit + unit // 2, c * unit + unit // 2, clr)
    rc_list.append(rc1)
    rc2 = MyRect((r+1) * unit + unit // 2, c * unit + unit // 2, clr)
    rc_list.append(rc2)
    rc3 = MyRect((r-1) * unit + unit // 2, c * unit + unit // 2, clr)
    rc_list.append(rc3)
    rc4 = MyRect(r * unit + unit // 2, (c-1) * unit + unit // 2, clr)
    rc_list.append(rc4)
    rc5 = MyRect(r * unit + unit // 2, (c+1) * unit + unit // 2, clr)
    rc_list.append(rc5)

Init()

def on_key_down(key):
    global ten_x,ten_y,rc_list
    if key == keys.ESCAPE:
        quit()
    elif key == keys.W:
        ten_y-=1
        if ten_y<=-1:
            ten_y=4
        rc_list=[]
        Init()
    elif key == keys.S:
        ten_y+=1
        if ten_y>=5:
            ten_y=0
        rc_list=[]
        Init()
    elif key == keys.A:
        ten_x-=1
        if ten_x<=-1:
            ten_x=4
        rc_list=[]
        Init()
    elif key == keys.D:
        ten_x+=1
        if ten_x>=5:
            ten_x=0
        rc_list=[]
        Init()

def draw():
 #   global GameOver
    screen.clear()
    screen.fill(BACK_COLOR)
    for rc in rc_list:
        rc.Draw()